//
//  LoadViewController.m
//  XiangMuB
//
//  Created by lanou3g on 16/8/15.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "LoadViewController.h"
#import "zhuceViewController.h"
#import "NSObject+alertView.h"
#import "loadShare.h"
#import "RootTabBarViewController.h"
#import "SettingViewController.h"
#import <AVOSCloud/AVOSCloud.h>
#import "ForgetViewController.h"
@interface LoadViewController ()
@property (strong, nonatomic) IBOutlet UITextField *nameTextFired;//用户名
@property (strong, nonatomic) IBOutlet UITextField *passwordTextFired;//密码


@end

@implementation LoadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    

    
}

//注册
- (IBAction)zhuce:(UIButton *)sender {
    
    zhuceViewController *zhuce = [zhuceViewController new];
   
    
    [self.navigationController pushViewController:zhuce animated:YES];
    

}


//登录
- (IBAction)login:(UIButton *)sender {
    /*
     
     qwe1234
     qwer12
     
     
     
     */
    
    
    if ([self.nameTextFired.text isEqualToString:@""] ||[self.passwordTextFired.text isEqualToString:@""] ) {
        
        [NSObject alterString:@"用户名或密码不能为空"];
        
         [loadShare shareLoad].load = NO;
    }else{
        
        
        
        
        
        [AVUser logInWithUsernameInBackground:self.nameTextFired.text   password:self.passwordTextFired.text block:^(AVUser *user, NSError *error) {
            if (user != nil) {
                
                
                     UIAlertController *alert =[UIAlertController alertControllerWithTitle:@"提示" message:@"恭喜,登录成功!" preferredStyle:(UIAlertControllerStyleAlert)];
                
                UIAlertAction *action  =[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
                    
                    
                    
                } ];
                
                UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                    
                    
                
                
                
                    
                    //[NSObject alterString:@"恭喜,登录成功!"];
                    
                    [loadShare shareLoad].load = YES;
                    [loadShare shareLoad].userName = self.nameTextFired.text;
                    
                    
                    RootTabBarViewController *root =[RootTabBarViewController new];
                    
            
                    
                    [self presentViewController:root animated:YES completion:nil];

                }];
                
                
                [alert addAction:action];
                
                [alert addAction:action1];
                
                
                [self presentViewController:alert animated:YES completion:nil];

                
                
                
                
                
            
            }
        }];
        
    }
}


//忘记密码
- (IBAction)forget:(UIButton *)sender {
    
    
    ForgetViewController *forget =[ForgetViewController new];
    
    [self.navigationController pushViewController:forget animated:YES];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
